package com.letfox.ad.service.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.letfox.ad.service.FINAccountNoviceService;
import com.letfox.finance.enums.FINDelEnums;
import com.letfox.finance.enums.FINIsDrawEnums;
import com.letfox.finance.model.FINNoviceInfo;
import com.letfox.finance.model.FINNoviceRlInout;
import com.letfox.finance.service.ComprehensiveService;
import com.letfox.finance.user.model.FinAccountRlUAccount;
import com.letfox.finance.user.service.FinAccountRlUAccountService;

@Service
public class FINAccontNoviceServiceImpl implements FINAccountNoviceService {
	@Autowired
	private ComprehensiveService comprehensiveService;
	@Autowired
	private FinAccountRlUAccountService finAccountRlUAccountService;
	
	/**
	 * 存储发票
	 */
	@Override
	public int saveFinNovice(FINNoviceInfo finNoviceInfo, String finInoutId)
			throws Exception {
		int i=0;
		finNoviceInfo.setFinNoviceId(UUID.randomUUID().toString());
		finNoviceInfo.setIsDraw(FINIsDrawEnums.FINIsDraw.TURE.getValue());
		finNoviceInfo.setCreateTime(new Date());
		finNoviceInfo.setUpdateTime(new Date());
		finNoviceInfo.setCreateBy("system");
		finNoviceInfo.setUpdateBy("system");
		finNoviceInfo.setDel(FINDelEnums.UDMDel.EFFECTIVE.getValue());
		//与财务账号关联
		FINNoviceRlInout finNoviceRlInout=new FINNoviceRlInout();
		finNoviceRlInout.setFinInoutId(finInoutId);
		finNoviceRlInout.setFinNoviceId(finNoviceInfo.getFinNoviceId());
		finNoviceRlInout.setCreateTime(new Date());
		finNoviceRlInout.setUpdateTime(new Date());
		finNoviceRlInout.setCreateBy("system");
		finNoviceRlInout.setUpdateBy("system");
		finNoviceRlInout.setDel(FINDelEnums.UDMDel.EFFECTIVE.getValue());
		i=comprehensiveService.provide_Invoice(finNoviceInfo, finNoviceRlInout);
		if(i<0)
			throw new Exception();
		return i;
	}
	
	/**
	 * 查询用户下发票列表
	 */
	@Override
	public List<FINNoviceInfo> getAcctountNoviceInfos(String accountId)
			throws Exception {
		FinAccountRlUAccount account = finAccountRlUAccountService.selectByAccountId(accountId);
		List list=comprehensiveService.Invoice_history(account.getFinAccountId());
		return list;
	}

}
